package com.atguigu.gmall.item.service.impl;

import com.atguigu.gmall.item.service.ItemService;
import com.atguigu.gmall.product.client.ProductFeignClient;
import com.atguigu.gmall.product.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * 远程调用商品微服务调用七项数据feign接口完成数据汇总
     *
     * @param skuId
     * @return
     */
    @Override
    public Map<String, Object> getItemInfo(Long skuId) {
        HashMap<String, Object> mapResult = new HashMap<>();
        //1.根据SkuID查询Sku商品信息
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
        mapResult.put("skuInfo", skuInfo);

        //2.根据商品所属三级分类ID查询分类信息
        BaseCategoryView categoryView = productFeignClient.getCategoryView(skuInfo.getCategory3Id());
        mapResult.put("categoryView", categoryView);

        //3.根据SKuID查询Sku商品价格
        BigDecimal skuPrice = productFeignClient.getSkuPrice(skuId);
        mapResult.put("price", skuPrice);

        //4.根据商品SpuID查询海报图片列表
        List<SpuPoster> spuPosterList = productFeignClient.getSpuPosterBySpuId(skuInfo.getSpuId());
        mapResult.put("spuPosterList", spuPosterList);

        //5.根据skuId查询当前SKU商品包含平台属性列表(包含属性值)
        List<BaseAttrInfo> attrList = productFeignClient.getAttrList(skuId);
        mapResult.put("skuAttrList", attrList);

        //6.查询SPU商品所有销售属性,查询指定SKU销售属性选中效果
        List<SpuSaleAttr> spuSaleAttrList = productFeignClient.getSpuSaleAttrListCheckBySku(skuId, skuInfo.getSpuId());
        mapResult.put("spuSaleAttrList", spuSaleAttrList);

        //7.在一组SPU商品下 切换不同SKU字符串
        String skuValueIdsMap = productFeignClient.getSkuValueIdsMap(skuInfo.getSpuId());
        mapResult.put("valuesSkuJson", skuValueIdsMap);

        return mapResult;
    }
}
